package cn.summit;

import java.io.IOException;
import java.util.Locale;
import java.util.Map;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.OrderComparator;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.io.Resource;

/**
 * @author summit
 * @since 2022/6/10 14:11
 */
public class ApplicationContextTest {

	public static void main(String[] args) throws IOException {
		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);

//        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
//        beanDefinition.setBeanClass(UserService.class);
//        beanDefinition.setScope("prototype");
//        applicationContext.registerBeanDefinition("userService", beanDefinition);

//        AnnotatedBeanDefinitionReader annotatedBeanDefinitionReader = new AnnotatedBeanDefinitionReader(applicationContext);
//        annotatedBeanDefinitionReader.register(UserService.class);

//        ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(applicationContext);
//        int scan = scanner.scan("cn.summit");
//        System.out.println("共扫描到" + scan);
//        User1Service userService = (User1Service) applicationContext.getBean("user1Service");
//        userService.test();


//		// 国际化
//		System.out.println(applicationContext.getMessage("test", null, new Locale("en")));
//
//		// 资源加载
//		Resource resource = applicationContext.getResource("classpath:messages_en.properties");
//		System.out.println(resource.contentLength());

		// 环境变量
		Map<String, Object> systemEnvironment = applicationContext.getEnvironment().getSystemEnvironment();
		System.out.println(systemEnvironment);

		Map<String, Object> systemProperties = applicationContext.getEnvironment().getSystemProperties();
		System.out.println(systemProperties);

		MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
		System.out.println(propertySources);

//		OrderComparator



	}
}
